// ==UserScript==
// @name         Automatically select the first tab in the online spreadsheet
// @name:zh      在线表格自动选中第一个tab
// @namespace    https://gitee.com/fengdiewang/tampermonkey-scripts#%E6%8E%A5%E5%8F%97
// @homepage     https://gitee.com/fengdiewang/tampermonkey-scripts/blob/master/02_tencentDoc/index.js
// @updateURL    https://gitee.com/fengdiewang/tampermonkey-scripts/raw/master/02_tencentDoc/index.js
// @downloadURL  https://gitee.com/fengdiewang/tampermonkey-scripts/raw/master/02_tencentDoc/index.js
// @version      2025-06-11_04
// @description  try to take over the world!
// @description:zh  尝试夺取世界！
// @author       Wang Fengdie
// @match        https://docs.qq.com/sheet/*
// @icon         https://docs.gtimg.com/docs-design-resources/document-management/tencent-docs/favicon/application-vnd.tdocs-apps.sheet.png
// @grant        none
// @run-at document-idle
// ==/UserScript==

(function () {
  "use strict";
  //    只对任务拆分的表格生效
  if (!document.title.includes("任务拆分")) {
    return;
  }
  //   使用定时器 防止脚本执行时没有dom
  setTimeout(() => {
    const tabsDom = document.querySelector(".docs-tab-bar-scrollable-scroller");
    const newTabDom = tabsDom.firstChild;
    const newId = newTabDom.firstChild.dataset.tabId;
    // 如果已经是最新的tab，就直接返回
    if (window.location.href.includes(newId)) {
      return;
    }
    setTimeout(() => {
      window.location.href = `${window.location.origin}${window.location.pathname}?tab=${newId}`;
    }, 100);
  }, 1000);
})();
